import { MessageBox } from "mint-ui";
const mutations = {
    //定义修改状态的方法，是唯一的
    changeIsLogin(state, data) {
        state.isLogin = data;
    },
    changeIndexListDatas(state, data) {
        state.indexListDatas = state.indexListDatas.concat(data)
    },
    changeIsLoading(state, data) {
        state.isLoading = data
    },
    changeCategoryLeftDatas(state, data) {
        state.categoryLeftDatas = data
    },
    changeCategoryRightDatas(state, data) {
        state.categoryRightDatas = data
    },
    changeCategoryListDatas(state, data) {
        state.categoryListDatas = state.categoryListDatas.concat(data)
    },
    changeBrandListDatas(state, data) {
        state.brandListDatas = data
    },
    changeDetailDatas(state, data) {
        state.detailDatas = data
    },
    changePosterImg(state, data) {
        state.posterDatas = data
    },
    changeCartDatas(state, data) {
        if (data) {
            state.cartDatas.unshift(data)
        }
        localStorage.setItem("carts", JSON.stringify(state.cartDatas))
    },
    //点击产品列表前的单选按钮
    changeSelect(state, data) {
        console.log(data);
        // state.cartDatas = data
        state.cartDatas[data.index] = data.cart

        //every()
        let isSelectAll = state.cartDatas.every((item) => {
            return item.isSelect == true
        })
        state.selectAll = isSelectAll
        localStorage.setItem("selectall", JSON.stringify(state.selectAll))
        localStorage.setItem("carts", JSON.stringify(state.cartDatas))
    },
    //点击全选按钮
    selectAllFn(state) {
        state.selectAll = !state.selectAll
        state.cartDatas.forEach((item) => {
            item.isSelect = state.selectAll
        })
        localStorage.setItem("selectall", JSON.stringify(state.selectAll))
        localStorage.setItem("carts", JSON.stringify(state.cartDatas))
    },
    // 点击+
    addFn(state, index) {
        state.cartDatas[index].value++
            localStorage.setItem("carts", JSON.stringify(state.cartDatas))
    },
    jianFn(state, index) {
        if (state.cartDatas[index].value <= 1) {
            state.cartDatas[index].value = 1
        } else {
            state.cartDatas[index].value--
        }
        localStorage.setItem("carts", JSON.stringify(state.cartDatas))

    },
    deleteFn(state, index) {
        // MessageBox
        MessageBox.confirm('亲，您确定要放弃该宝贝吗?').then(() => {
            console.log("点击了确定按钮");
            state.cartDatas.splice(index, 1)
            localStorage.setItem("carts", JSON.stringify(state.cartDatas))
        }, () => {
            console.log("点击了取消按钮");
        });

    }
};


export default mutations;